package com.leo.train.business.controller.admin;

import com.leo.train.business.dto.SkTokenDto;
import com.leo.train.business.entity.SkToken;
import com.leo.train.business.service.SkTokenService;
import com.leo.train.common.resp.CommonResp;
import com.leo.train.common.resp.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/skToken")
public class SkTokenAdminController {
    @Autowired
    private SkTokenService skTokenService;
    /**
     * 查询秒杀令牌列表
     * @param skTokenDto
     * @return
     */
    @GetMapping("/list")
    public CommonResp<PageResult<SkToken>> list(SkTokenDto skTokenDto) {
        PageResult<SkToken> pageResult = skTokenService.list(skTokenDto);
        return new CommonResp<>(pageResult);
    }

    /**
     * 修改秒杀令牌
     * @param skToken
     * @return
     */
    @RequestMapping("/update")
    public CommonResp update(@RequestBody SkToken skToken) {
        skTokenService.update(skToken);
        return new CommonResp<>();
    }

    /**
     * 查看详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public CommonResp<SkToken> detail(Long id) {
        SkToken skToken = skTokenService.detail(id);
        return new CommonResp<>(skToken);
    }
}
